import Vue from 'vue'
import Vuex from 'vuex'
import { getToken } from '@/utils/auth'
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex)

const store = new Vuex.Store({
    plugins: [
        createPersistedState({
            storage: window.localStorage
        })
    ],
    state: {
        token: getToken() ? getToken() : "",
        userinfo: {}
    },
    mutations: {
        SET_USERINFO(state, newval) {
            state.userinfo = newval
        },
        SET_TOKEN(state, newval) {
            state.token = newval
        },
    },
})

export default store